define(function(require, exports, module){
	myApp  = seajs.data.vars.myApp;
	$$  = seajs.data.vars.dom;
	mainview = seajs.data.vars.mainview;
	
	function page() {
		var _basePage=this;
		this.init=function(){
			
			//获取客户id
			var id = $$('#id').val();
			var url = "/m/customer/customerinfo";
			
			//企业详细信息
			customerobj = new Vue({
				el:'#customerinfo',
				data:{info:{},param:{}},
				created:function(){
					var _self=this;
					$$.ajax({
						url:url,
						method:"POST",
						async:false,
						data:{id:id},
						success:function(data){
							if(data!=null){
								_self.info = eval("(" + data +")");
							}
						}
					});
				},
				mounted:function(){},
				beforeUpdate:function(){},
				updated:function(){},
				methods: {},
			});
			
			$$(document).on("click",".iteminfo",function(){
				 //根据id展示对应页面
				 var id = $$(this).attr("data");
				 //获取字段
				 var namedata = $$(this).attr("namedata");
				 //加载页面
				 mainview.router.loadContent($$("#"+id).html());
				 //在基本的input框中,不一样的只有QQ和微信
				 for (var prop in customerobj.info) {
					 if (prop == namedata) {
						//成熟等级(state),客户来源(source),客户分类(level)是选择
						 if (namedata === 'state' || namedata === 'source' || namedata === 'level' || namedata === 'paperspurpose') {
							 $$("input[name='"+ namedata +"']").each(function(){
								 $$("input[value='"+ customerobj.info[prop] + "']").attr("checked",true);
							 });
							 break;
						 } else {
							 $$(".customer"+prop).eq(1).val(customerobj.info[prop]);
							 break;
						 }
					 }
				 }
			 });
			
			//点击保存修改
			 $$(document).on("click",".itemsave",function(){
				 
				 //获取字段
				 var namedata = $$(this).attr("namedata");
				 //获取值
				 var value;
				 if (namedata === 'state' || namedata === 'source' || namedata === 'level' || namedata === 'paperspurpose') {
					 value = $$("input[name='"+ namedata +"']:checked").eq(1).val();
				 } else {
					 value = $$(".customer"+namedata).eq(1).val();
				 }
				 for (var prop in customerobj.info) {
					 if (prop == namedata) {
						 alert(1);
						 customerobj.info[prop] = value;
						 break;
					 }
				 }
				//把customerobj.info中的信息拷贝到一个新的对象中
				 var paramdata = JSON.parse(JSON.stringify(customerobj.info));
				//删除对象中不需要的key
				 delete paramdata["contactsItem"];
				 $$.ajax({
					 type : "post",
					 url : "/m/customer/updatecustomer",
					 data : paramdata,
					 dataType : "json",
					 async:false,
					 success : function(data){
						 myApp.toast().show("更新成功");
					 }
				 });
				 
			 });
			
			
			
			
			
		}
	}
	module.exports=new page();
});